package ui;
//-*- mode:java; Encoding:utf8n -*-
//http://terai.xrea.jp/Swing/SortableTable.html

public class TestModel extends SortableTableModel {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public TestModel(String[] str, int row) {
		super(str, row);
		// TODO 自動生成されたコンストラクター・スタブ
	}

	TestModel() {
		super();
		// TODO 自動生成されたコンストラクター・スタブ
	}
	private static final ColumnContext[] columnArray = {
        new ColumnContext("id",     Integer.class, false),
        new ColumnContext("Title",    String.class,  false),
        new ColumnContext("Play",    Integer.class,  false),
        new ColumnContext("Rating", Integer.class,  false),
        new ColumnContext("Rank",     Integer.class, false),
        new ColumnContext("Average",     Float.class, false),
        new ColumnContext("Designer",    String.class,  false),
        new ColumnContext("Year", Integer.class,  false),
        new ColumnContext("Min",     Integer.class, false),
        new ColumnContext("Max",    Integer.class,  false),
        new ColumnContext("Time", Integer.class,  false)
    };
    private int number = 0;
    public void addTest(Test t) {
        Object[] obj = {new Integer(number), t.getName(), t.getComment()};
        super.addRow(obj);
        number++;
    }
    public boolean isCellEditable(int row, int col) {
        return columnArray[col].isEditable;
    }
    @SuppressWarnings("unchecked")
	public Class getColumnClass(int modelIndex) {
        return columnArray[modelIndex].columnClass;
    }
    public int getColumnCount() {
        return columnArray.length;
    }
    public String getColumnName(int modelIndex) {
        return columnArray[modelIndex].columnName;
    }
    private static class ColumnContext {
        public final String  columnName;
        public final Class   columnClass;
        public final boolean isEditable;
        public ColumnContext(String columnName, Class columnClass, boolean isEditable) {
            this.columnName = columnName;
            this.columnClass = columnClass;
            this.isEditable = isEditable;
        }
    }
}
class Test{
    private String name, comment;
    public Test(String name, String comment) {
        this.name = name;
        this.comment = comment;
    }
    public void setName(String str) {
        name = str;
    }
    public void setComment(String str) {
        comment = str;
    }
    public String getName() {
        return name;
    }
    public String getComment() {
        return comment;
    }
}
